package org.jeecg.modules.user.notice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.xkcoding.http.util.StringUtil;
import org.jeecg.modules.user.notice.entity.Carousel;
import org.jeecg.modules.user.notice.mapper.CarouselMapper;
import org.jeecg.modules.user.notice.service.CarouselService;
import org.jeecg.modules.utils.BikeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CarouselServiceImpl implements CarouselService {

    @Autowired
    private CarouselMapper carouselMapper;

    @Value("${application.domain}")
    public String domain;

    public String getDomain() {
        return domain;
    }

    public void setDomain(String domain) {
        this.domain = domain;
    }

    @Override
    public BikeResult getCarouselList(Integer type,String id) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("status","1");
        if (StringUtil.isNotEmpty(id)){
            qw.eq("id",id);
        }
        qw.eq("type",type);
        qw.orderByAsc("carousel_order");
        qw.orderByDesc("create_time");
        List<Carousel> carousels= carouselMapper.selectList(qw);
        if (carousels.size()!=0){
            //拼接图片地址
            carousels.forEach(
                    vs->{
                        vs.setFileUrl(domain+vs.getFileUrl());
                    }
            );
        }
        return BikeResult.ok("1","查询成功",carousels);
    }
}
